﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       Shpm.System.SysUserBean
 * 类型：       Bean
 * 功能说明：   验证权限
 * 作者：       谈震鸣
 * 创建日期：   2007/08/14
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
 */
using System;
using System.Web.UI.WebControls;
using System.Collections;
using Shpm.App.Commons.Db.Beans.Master;

namespace Shpm.System
{
    [Serializable()]
    public class SysUserBean
    {
        private MstSysUserBean mstSysUserBean = null;
        private MstEmployeeBean employeeBean = null;
        private IList permissions = null;
        private IList groups = null;
        private IList departments = null;

        public SysUserBean()
        {
        }

        public MstSysUserBean getMstSysUserBean()
        {
            return mstSysUserBean;
        }

        public void setMstSysUserBean(MstSysUserBean mstSysUserBean)
        {
            this.mstSysUserBean = mstSysUserBean;
        }

        public void setEmployeeBean(MstEmployeeBean employeeBean)
        {
            this.employeeBean = employeeBean;
        }

        public MstEmployeeBean getEmployeeBean()
        {
            return this.employeeBean;
        }

        public void addPermission(SysPermission permission)
        {
            if (this.permissions == null) this.permissions = new ArrayList();
            this.permissions.Add(permission);
        }

        public bool CheckPermission(SysPermission permission)
        {
            if (this.mstSysUserBean != null && mstSysUserBean.SysUserId == Constants.SYSTEM_ID)
                return true;
            else if (this.groups != null)
            {
                IEnumerator enm = this.groups.GetEnumerator();
                while (enm.MoveNext())
                {
                    MstGroupBean dataBean = (MstGroupBean)enm.Current as MstGroupBean;
                    if (dataBean.GroupId == Constants.SYSTEM_GROUP_ID)
                        return true;
                }
            }
            return this.permissions != null && this.permissions.Contains(permission);
        }

        public IList getGroups()
        {
            return groups;
        }

        public void setGroups(IList groups)
        {
            this.groups = groups;
        }

        public IList getDepartments()
        {
            return this.departments;
        }

        public void setDepartments(IList departments)
        {
            this.departments = departments;
        }
    }

}
